package org.ruanjj.mergetwolists;

import org.ruanjj.linkedlist.ListNode;

public class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2){
        ListNode resListNode = new ListNode(-1);
        ListNode cur = resListNode;
        while(list1 != null && list2 != null){
            if(list1.val > list2.val){
                resListNode.next = list2;
                list2 = list2.next;
            }else{
                resListNode.next = list1;
                list1 = list1.next;
            }
            resListNode = resListNode.next;
        }
        resListNode.next = list1 == null?list2:list1;
        return cur.next;
    }
}
